var vueInstan
(function(){
    var week = HQ.config.language.week[language];
    var month = HQ.config.language.month[language];

    var height = $(window).height() - 73;
    var width = $(window).width();
    var is_ajax = 0;
    var is_sea_val = 0;
    var sea_word = "";
    var sea_adult = sea_adult_tmp = 2;
    var sea_child = sea_child_tmp = 0;
    var sea_child_age = sea_child_age_tmp = [];
    var sea_room_num = sea_room_num_tmp = 1;
    var sea_citizenship = 'CN';
    var d_child_age_html = $('.d-child-age').html();
	var chkin = $("#from").val();
	var chkout = $("#to").val();
	var is_complete = 0;
	var tmp_ajax = "";
	var poi_channel = "";
    var search_citizenship = config.citizenship || '',
        search_citizenship_name = config.citizenship_name || '';
    var icons = {
	    'city':HQ.config.language.index_tips[language][0],
	    'hotel':HQ.config.language.index_tips[language][1],
	    'area':HQ.config.language.index_tips[language][2],
	    'attr':HQ.config.language.index_tips[language][3],
	    'country':HQ.config.language.index_tips[language][4],
        'region':HQ.config.language.index_tips[language][5],
        'island':HQ.config.language.index_tips[language][6],
		'poi':HQ.config.language.index_tips[language][7],
	};
	if(height > $("#J_index_cont").outerHeight(true)){
		$("#J_index").css({height : height});
	}
	if(width*1440/2560 > height){
		$("#J_index_img").css({width : width, height : width*1440/2560, top : -(width*1440/2560 - height)/2, left : 0});
	}else{
		$("#J_index_img").css({width : height*2560/1440, height : height, left : -(height*2560/1440 - width)/2, top : 0});
	}
	
	$(window).resize(function(){
		height = $(window).height() - 73;
		width = $(window).width();
		if(height > $("#J_index_cont").outerHeight(true)){
			$("#J_index").css({height : height});
		}
		if(width*1440/2560 > height){
			$("#J_index_img").css({width : width, height : width*1440/2560, top : -(width*1440/2560 - height)/2, left : 0});
		}else{
			$("#J_index_img").css({width : height*2560/1440, height : height, left : -(height*2560/1440 - width)/2, top : 0});
		}
	});

	// 首页 -> 搜索记录 -> 显示/隐藏
    $('.J_search_history_switch').click(function () {
        var _this = $(this),
            _isShow = _this.attr('data-isshow') === '1',
            historyBox = $('.J_search_history_box'),
            _children = _this.find('i');
        if(_isShow) {
            _this.attr('data-isshow', 0);
            historyBox.slideDown('slow');
            _children.removeClass('rotate-180');
        } else {
            _this.attr('data-isshow', 1);
            historyBox.slideUp('slow', function () {
            });
            _children.addClass('rotate-180');
        }
        return false
    });

    // 首页 -> 搜索记录 -> 清空对话框
    $('.J_clear_search_history').click(function () {
        $(this).find('.J_clear_search_history_dialog').fadeIn('slow');
        return false
    });

    // 首页 -> 搜索记录 -> 确认清空
    $('.J_clear_search_history_confirm').click(function () {
        $.ajax({
            url : "/haoqiao/delete_records",
            type : "get",
            dataType : "json",
            success : function(data){
                if(data.code==0){
                    $(".J_search_history_switch").attr("data-isshow",0);
                    $('.J_search_history_box').fadeOut();
                    $(".search-history-switch-wrap").fadeOut();
                    hq_toast.show('success', data.msg, 2000);
                }else{
                    hq_toast.show('warn', data.msg, 2000);
                }
            },
            error : function(jqXHR, textStatus, errorThrown){

            }
        });
        $(this).parents('.J_clear_search_history_dialog').fadeOut('slow');
        tj && tj.btn_click("browserhistory_clear"+ "\thomepage\t"+config.dist_id+"|"+config.user_id);
        return false
    });

    // 首页 -> 搜索记录 -> 取消清空
    $('.J_clear_search_history_cancel').click(function () {
        $(this).parents('.J_clear_search_history_dialog').fadeOut('slow');
        return false
    });
    
    // 隐藏除国籍列表以外的弹框
    function hideSel(){
        $(".J_sel_num").attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J-room-pro").attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $('.J-top-room-pro').attr('data-isshow',0);
        $('#J_popup_city, #J-top-more-normal-list,.J_top_room_sel_win_room,#J_sea_box,.J_room_sel_win, #J_show_null_tip, .d-mod-room-win').hide()
    }
    // 国籍列表显示隐藏
    $('.J_sel_num_citizenship').click(function () {
        var is_show = $(this).attr("data-isshow");
        // 更改其他弹框状态
        hideSel();
        $(this).attr("data-isshow", 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(this).next().hide();

        if(is_show == 0){
            $(this).attr("data-isshow", 1).find('.icon-bottom-arrow-s').removeClass('rotate-180');
            $(this).next().show();
            $('.d-room-sea-form').find('#J-more-normal-list').hide();
            $('.d-room-sea-form').find('#J_more_option_num').hide();
        }
        return false;
    })
    //国籍相关事件
    $("#J_nationality").click(function(e){
        // 点击input选中所有文字
        $(this).select();
        // 更改其他弹框状态
        hideSel();
        // 更改箭头方向
        $('.J_sel_num_citizenship').attr("data-isshow", 1);
        $(this).next('.icon-bottom-arrow-s').addClass('rotate-180');
        e.stopPropagation();
        // 移除（请选择办理入住手续的客人国籍）错误提示
        $('.room_sel_win_citizenship-list-remind').removeClass('error_color');
        // 显示菜单
        $("#J_room_sel_win_nationality").show();
        return false;

    }).keyup(function(e){
        // 输入清空国籍变量
        search_citizenship = "";
        search_citizenship_name = "";
        // 移除错误提示边框
        $(".J_sel_num_citizenship").removeClass("index-date-error");
        // 去掉字符串起始和结尾的空格
        var val = $.trim($(this).val());
        if(val){
            $(this).css({color: "#333"});
            // 字符串匹配
            $.getJSON("/hoteldetail/citizenship_list?term=" + val, function(data) {
                $(".room_sel_win_citizenship_pre").hide();
                $(".room_sel_win_citizenship_bre").remove();
                if(data.length) {
                    // length >= 0, 隐藏找不到相关国籍提示
                    $("#J_show_null_tip").hide();
                    // push国籍
                    for(var i=0;i<data.length;i++){
                        $("#J_room_sel_win_nationality").append('<li class="room_sel_win_citizenship_bre"><a data-val="'+data[i].id+'" data-type="cs" href="javascript:;">'+data[i].value+'</a></li>');
                    }
                }else{
                    // length <= 0, 显示找不到相关国籍提示
                    $("#J_show_null_tip").show();
                }
            });
        }else{
            // value为空，1.显示 => 国家，2.隐藏bre => 已匹配的国家，3.隐藏找不到相关国籍提示
            $(".room_sel_win_citizenship_pre").show();
            $(".room_sel_win_citizenship_bre").remove();
            $("#J_show_null_tip").hide();
        }

    }).blur(function(){
        var val = $(this).val();
        // 更改箭头方向
        $(this).next('.icon-bottom-arrow-s').addClass('rotate-180');
        if(!val) {
            // 1.显示 => 国家，2.隐藏bre => 已匹配的国家，3.填充国籍，4.移除错误提示
            $(".room_sel_win_citizenship_pre").show();
            $(".room_sel_win_citizenship_bre").remove();
            $("#J_nationality").val($("#J_nationality").attr("data-placeholder")).css({color: "#999"});
            $('.J_sel_num_citizenship').parents().removeClass("index-date-error");
        }
    });
    // 选择国籍事件
    $(".J_room_sel_win_nationality").on('click', 'a', function(){
        // 保存val
        search_citizenship = $(this).attr("data-val");
        search_citizenship_name = $(this).html();
        // 填充val, 移除错误提示，隐藏列表
        $("#J_nationality").val($(this).html()).attr('data-val', search_citizenship).css({color : "#333"});
        $('#J_nationality_ipt').val(search_citizenship);
        $('.J_sel_num_citizenship').removeClass("index-date-error");
        $("#J_room_sel_win_nationality").hide();
        // tj && tj.sea_click("select|"+ $("#J_nationality").val() +"\thoteldetail|city="+ config.city);
        // is_sea_val = 0;
        return false;
    });

	// 防止相同事件快速重复触发
	var _timer = {};
	function delay_till_last(id, fn, wait) {
		if (_timer[id]) {
			window.clearTimeout(_timer[id]);
			delete _timer[id];
		}
		return _timer[id] = window.setTimeout(function() {
			fn();
			delete _timer[id];
		}, wait);
	}

	//tips索引
	var key_index = 0;

	// 变更搜索类型&图标
    function resetSearchTypeIcon (type) {
        var _box = $('.J_search_icon_box'),
            _text = _box.find('em'),
            _icon = _box.find('i');
        if(type) {
            if(!_icon.hasClass('icon-' + type)) {
                _icon.removeClass().addClass('iconfont icon-search-' + type);
            }
            _text.text(icons[type]);
        } else {
            _icon.removeClass();
            _text.text('');
        }
    }


    // 热门推荐点击 2018-7-5 daiem
    $('#J_popup_city').on("click", ".se-recommend-hot-list a", function(){
        $("#J_tips").hide();
        if(/<i>/i.test($(this).html())){
            var city = $(this).attr("data-name").replace(/^<span>(.*?)<i>.*?<\/span>$/i, "$1");
        }else{
            var city = $(this).attr("data-name").replace(/^<span>(.*?)<\/span>$/i, "$1");
        }
        $("#J_city").val(city).css({color : "#333"}).removeClass("index-date-error");
        resetSearchTypeIcon('city');
        $("#J_popup_city").hide();
        $("#J_from").attr("action", "/"+ $(this).attr("data-urlname") +"_c"+ $(this).attr("data-val") +"/");
        tj && tj.sea_click("hot|热门城市:"+ city +"\thomepage");
        config.search_data = "city|" + $(this).attr("data-val");
        config.urlname = $(this).attr("data-urlname");
        return false;
    });

    // 最近搜索点击 2018-7-5 daiem
    $('#J_popup_city').on("click", ".se-recently-se-list a", function(){
        $("#J_tips").hide();
        if(/<i>/i.test($(this).html())){
            var city = $(this).attr("data-name").replace(/^<span>(.*?)<i>.*?<\/span>$/i, "$1");
        }else{
            var city = $(this).attr("data-name").replace(/^<span>(.*?)<\/span>$/i, "$1");
        }
        $("#J_city").val(city).css({color : "#333"}).removeClass("index-date-error");
        resetSearchTypeIcon('city');
        $("#J_popup_city").hide();
        $("#J_from").attr("action", "/"+ $(this).attr("data-urlname") +"_c"+ $(this).attr("data-val") +"/");
        // tj && tj.sea_click("hot|热门城市:"+ city +"\thomepage");
        config.search_data = "city|" + $(this).attr("data-val");
        config.urlname = $(this).attr("data-urlname");
        return false;
    });

    // 最近浏览、常订酒店 2018-7-5 daiem
    $('#J_popup_city').on('click',".se-history-list .se-history-li,.se-frequently-hotel-list .se-frequently-hotel",function(e){
        $("#J_tips").hide();
        if(/<i>/i.test($(this).html())){
            var city = $(this).attr("data-name").replace(/^<span>(.*?)<i>.*?<\/span>$/i, "$1");
        }else{
            var city = $(this).attr("data-name").replace(/^<span>(.*?)<\/span>$/i, "$1");
        }
        $("#J_city").val(city).css({color : "#333"}).removeClass("index-date-error");
        resetSearchTypeIcon('hotel');
        $("#J_popup_city").hide();
        $("#J_from").attr("action", "/"+ $(this).attr("data-urlname") +"_c"+ $(this).attr("data-cityid") + "/" + $(this).attr("data-id") + ".html");
        var index = parseInt($(this).index()) + 1;
        tj && tj.sea_click($(this).attr("data-type") + "|推荐酒店:"+ $(this).attr("data-id") +":"+ index +"\thomepage");
        config.search_data = "hotel|" + $(this).attr("data-cityid")+"|" +$(this).attr("data-id");
        config.urlname = $(this).attr("data-urlname");
        return false;
    });

    // 搜索弹窗查看更多 2018-7-3 daiem
    $(document).on('mouseenter',".ser-r-con", function(e){//debugger;
        e.stopPropagation();
        $("#J_sea_box .ser-li").removeClass('ser-li-current');
        $('.ser-r-con').removeClass('ser-r-con-hover');
        $(this).addClass('ser-r-con-hover');
        var _this = $(this);
        if (_this.data('nums') > 0 && _this.siblings('.ser-r-con-more').is(':hidden')) {
            var ser_r_con_h_arr = [];
            $('#J_sea_box .ser-row').each(function(){
                ser_r_con_h_arr.push($(this).find('.ser-r-con').height());
            });
            $('.ser-row .ser-r-con-more').hide();
            $('#ser-r-con-more-tran').remove();
            // 计算定位
            var pos_container_top = 0, pos_triangle_top = 0;
            var ser_row_index    = _this.parents('.ser-row').index() - 1;
            var ser_r_con_more_h = _this.siblings('.ser-r-con-more').height();
            var current_this_h   = ser_r_con_h_arr[ser_row_index];
            if (ser_row_index > 0) {
                var sum_h = 0;
                for (var i = 0; i <= ser_row_index; i++) {
                    sum_h += ser_r_con_h_arr[i];
                }
                // 如果更多弹框高度小于等于父级框高度时
                if (ser_r_con_more_h <= current_this_h) {
                    pos_container_top = Math.round((current_this_h - ser_r_con_more_h) / 2);
                    pos_triangle_top  = Math.round((ser_r_con_more_h - 16) / 2);
                } else {
                    var current_this_mid_offset_top = Math.round(sum_h - current_this_h / 2);
                    // 如果更多弹框一半高度小于等于距顶父弹框的距离
                    if (current_this_mid_offset_top > Math.round(ser_r_con_more_h / 2)) {
                        pos_container_top = -Math.round((ser_r_con_more_h - current_this_h) / 2);
                        pos_triangle_top  = Math.round((ser_r_con_more_h - 16) / 2);
                    } else {
                        pos_container_top = current_this_h - sum_h;
                        pos_triangle_top  = Math.round(current_this_mid_offset_top - 8);
                    }
                }
            } else {
                if (current_this_h > ser_r_con_more_h) {
                    pos_container_top = (current_this_h - ser_r_con_more_h) / 2;
                    pos_triangle_top  = Math.round((ser_r_con_more_h - 16) / 2);
                } else {
                    pos_container_top = 0;
                    pos_triangle_top  = Math.round((current_this_h - 16) / 2);
                }
            }
            var _style = '<style id="ser-r-con-more-tran">.ser-r-con-more:before{box-sizing: content-box;width: 0px;height: 0px;position: absolute;top: ' + pos_triangle_top + 'px;left: -16px;padding:0;border-bottom:8px solid transparent;border-top:8px solid transparent;border-left:8px solid transparent;border-right:8px solid #FFFFFF;display: block;content:"";z-index: 12;}';
            _style += '.ser-r-con-more:after{box-sizing: content-box;width: 0px;height: 0px;position: absolute;top: ' + (pos_triangle_top - 1) + 'px;left: -18px;padding:0;border-bottom:9px solid transparent;border-top:9px solid transparent;border-left:9px solid transparent;border-right:9px solid #cccccc;display: block;content:"";z-index:10}</span>';
            $('body').append(_style);
            $('#J_sea_box .ser-row .js_ser-r-con-hover').removeClass('js_ser-r-con-hover');
            _this.addClass('js_ser-r-con-hover').siblings('.ser-r-con-more').css('top', pos_container_top+'px').show();
        }
    }).on('mouseleave', ".ser-r-con", function(e){
        e.stopPropagation();
        var _this = $(this);
        setTimeout(function(){
            if (!_this.siblings('.ser-r-con-more').is(":hover")) {
                _this.removeClass('ser-r-con-hover').siblings('.ser-r-con-more').hide();
                $('#J_sea_box .ser-row .js_ser-r-con-hover').removeClass('js_ser-r-con-hover');
            } else {
                _this.siblings('.ser-r-con-more').unbind().on('mouseleave', function (e) {
                    setTimeout(function(){
                        $(this).hide().siblings('.ser-r-con').removeClass('js_ser-r-con-hover ser-r-con-hover');
                    }, 300);
                });
            }
        }, 300);
    });

	// 搜索弹窗最底部查看全部搜索结果 2018-7-3 daiem
	$("#J_sea_box").on('click', '.ser-row-bot', function(){
        $("#J_city").val(sea_word);
        var uri = "/cz_"+ encodeURIComponent(sea_word);
        window.location.href = uri;
        return false;
    });

	// 搜索弹窗元素鼠标移动背景样式切换 2018-7-5 daiem
    $(document).on('mouseover',"#J_sea_box .ser-li", function(){
        $("#J_sea_box .ser-li").removeClass('ser-li-current ser-li-current-top ser-li-current-bot ser-li-current-all');
        if ($(this).parents('div.ser-r-con-more').html()) {
            var slilen = $(this).parents('div.ser-r-con-more').find('.ser-li').length;
            var sliindex = $(this).index();
            if (slilen > 1) {
                if (sliindex === 0) {
                    $(this).addClass('ser-li-current ser-li-current-top');
                }else if ((sliindex + 1) === slilen) {
                    $(this).addClass('ser-li-current ser-li-current-bot');
                } else {
                    $(this).addClass('ser-li-current');
                }
            } else {
                $(this).addClass('ser-li-current ser-li-current-all');
            }
        } else {
            $(this).addClass('ser-li-current');
        }
    });

	// 搜索弹窗内容 2018-7-4 daiem
    /*$("#J_sea_box").on("click", '.ser-li', function(e){
        e.stopPropagation();
        $("#J_tips").hide();
        sea_timer && clearTimeout(sea_timer);
        tmp_ajax.abort();
        restartflag = 0;
        search_is_complete = 0;
        $(this).find('.ser-m-con-right').remove();
        $("#J_city").val($(this).text()).css({color : "#333"}).removeClass("index-date-error");
        var realType = $(this).attr("data-real-type");
        if(realType && realType === "island") {
            resetSearchTypeIcon('island');
        }else{
            resetSearchTypeIcon($(this).attr("data-type"));
        }
        $("#J_city_hid").val($(this).attr("data-cityid")).attr("name", "city");
        $("#J_sea_box").hide();

        var id = $(this).attr("data-id");
        var type = $(this).attr("data-type");
        var city_id = $(this).attr("data-cityid");
        var urlname = $(this).attr("data-urlname");
        var is_alias = $(this).attr("data-alias");
        if(type=='poi'){
            var lat = $(this).attr("data-lat");
            var lan = $(this).attr("data-lan");
            var dataname = $(this).attr("data-name");
            poi_channel = "|"+$(this).attr("data-channel");
            $("#J_lat").val(lat);
            $("#J_lan").val(lan);
            $("#J_type").val(type);
            $("#J_name").val(dataname);
        }
        if(is_alias == 1){
            $("#J_alias").val($(this).attr("data-name")).attr("name", "alias");
        }else{
            $("#J_alias").attr("name", "");
        }

        config.search_type = type;
        //alert(type);
        if(type == "country"){
            $("#J_from").attr("action",urlname +".html");
            config.search_type = config.search_type + "|"  + id;
        }else if(type == "region"){
            $("#J_from").attr("action", urlname +".html");
            config.search_type = config.search_type + "|"  + id;
        }else if(type == "city"){
            $("#J_from").attr("action", urlname +"_c"+ city_id +"/");
            config.search_type = config.search_type + "|" + id;
        }else if(type == "area"){
            $("#J_from").attr("action", urlname +"_c"+ city_id +"/a"+ id);
            config.search_type = config.search_type + "|" + city_id + "|" +id;
        }else if(type == "hotel"){
            $("#J_from").attr("action", urlname +"_c"+ city_id +"/"+ id +".html");
            config.search_type = config.search_type + "|" + city_id + "|" +id;
        }else if(type == "attr"){
            $("#J_from").attr("action",urlname +"_c"+ city_id +"/attr"+ id);
            config.search_type = config.search_type + "|" + city_id + "|" +id;
        }else if(type == "poi"){
            $("#J_from").attr("action",urlname +"_c"+ city_id );
            config.search_type = config.search_type + poi_channel + "|" + city_id;
        }
        config.search_data = config.search_type;
        config.urlname = urlname;
        var chkin = $("#from").val();
        var chkout = $("#to").val();
        var room = $('#J_sel_room_num').val();
        var adult = $('#J_sel_room_adult').val();
        var child = $('#J_sel_room_child').val();
        var child_age = $('#J_sel_room_child_age').val();

        // 判断是否是搜索更多中的点击, 并记录日志
        var current_index = $(this).index() + 1, current_conp_index = $(this).parents('.ser-row').index(), iter_index = 1, total_sl_len = 0;
        if ($(this).parent().hasClass('ser-r-con-more')) {
            // 计算点击位置
            $('#J_sea_box .ser-row').each(function(){
                var sl_len   = $(this).find('.ser-m-con .ser-li').length;
                var sl_m_len = $(this).find('.ser-r-con').data('nums');
                total_sl_len += sl_len;
                if (iter_index == current_conp_index) {
                    current_index += total_sl_len;
                }
                total_sl_len += sl_m_len;
                ++iter_index;
            });
            tj && tj.sea_click("select_more|"+ $(this).attr("data-name") +"\thomepage\t"+config.dist_id+"|"+config.user_id+"|"+chkin+"|"+chkout+"|"+room+"|"+adult+"|"+child+"|"+"|"+child_age+"|\t"+$("#J_city").val()+"\t"+type+poi_channel+"|"+$(this).attr("data-id")+"\t"+current_index+"|"+total_sl_len);
        } else {
            // 计算点击位置
            $('#J_sea_box .ser-row').each(function(){
                var sl_len = $(this).find('.ser-m-con .ser-li').length;
                if (iter_index == current_conp_index) {
                    current_index += total_sl_len;
                }
                total_sl_len += sl_len;
                ++iter_index;
            });
            tj && tj.sea_click("select|"+ $(this).attr("data-name") +"\thomepage\t"+config.dist_id+"|"+config.user_id+"|"+chkin+"|"+chkout+"|"+room+"|"+adult+"|"+child+"|"+"|"+child_age+"|\t"+$("#J_city").val()+"\t"+type+poi_channel+"|"+$(this).attr("data-id")+"\t"+current_index+"|"+total_sl_len);
        }
        is_sea_val = 0;
    });
*/
    // 全部搜索结果下划线 2018-7-27 daiem
    $(document).on('mouseenter', "#J_sea_box .ser-row-bot", function () {
        $("#J_sea_box .ser-li").removeClass('ser-li-current');
        $("#J_sea_box .ser-row-bot span").css('text-decoration', 'underline');
    }).on('mouseleave', "#J_sea_box .ser-row-bot", function () {
        $("#J_sea_box .ser-row-bot span").css('text-decoration', 'none');
    });

    // 禁止搜索框非点击区域点击时事件冒泡 2018-7-27 daiem
    $("#J_sea_box,#J_popup_city").click(function(e){
        e.stopPropagation();
    });

    //城市输入框失去焦点
    $("#J_city").focus(function(){
        $(".J_room_sel_win").hide();
        $(".J_sel_num").attr("data-isshow",0);
        $(".J-room-pro").attr("data-isshow",0);
        if(is_sea_val == 0){
			$.ajax({ 
				type:"post", 
				url:"/ajax/get_search_recommend_hotel_v1", 
				data: {}, 
				dataType: 'json', 
				async : false,
				success:function(data){ 
					if(data.res == 0){
                        // 最近浏览recent_se_html
                        var is_history_show = false;
                        if(data.msg.history_html != ''){
                            $("#J_popup_city .se-history-list").html(data.msg.history_html).parents(".se-row").show();
                            $("#J_popup_city .index-se-con-recent").show();
                            tj && tj.sea_click("is_history|热门酒店:1\thomepage");
                            is_history_show = true;
                        }else{
                            $("#J_popup_city .se-history-list").parents(".se-row").hide();
                            tj && tj.sea_click("is_history|热门酒店:0\thomepage");
                        }
                        // 常订酒店
                        if(data.msg.frequently_html != ''){
                            $("#J_popup_city .se-frequently-hotel-list").html(data.msg.frequently_html).parents(".se-row").show();
                            $("#J_popup_city .index-se-con-recent").show();
                            tj && tj.sea_click("is_frequently|热门酒店:1\thomepage");
                            if (is_history_show) {
                                $("#J_popup_city .se-frequently-hotel-list").parents(".se-row").addClass('m-t13');
                            } else {
                                $("#J_popup_city .se-frequently-hotel-list").parents(".se-row").removeClass('m-t13');
                            }
                        }else{
                            $("#J_popup_city .se-frequently-hotel-list").parents(".se-row").hide();
                            tj && tj.sea_click("is_frequently|热门酒店:0\thomepage");
                        }
                        // 推荐城市
                        if(data.msg.recommend_city_html != ''){
                            $("#J_popup_city .se-recommend-hot-list").html(data.msg.recommend_city_html);
                        }
                        // 最近浏览
                        if(data.msg.recent_se_html != ''){
                            $("#J_popup_city .se-recently-se-list").html(data.msg.recent_se_html).parents(".se-row").show();
                            // tj && tj.sea_click("is_history|热门酒店:1\thomepage");
                        }else{
                            $("#J_popup_city .se-recently-se-list").parents(".se-row").hide();
                            // tj && tj.sea_click("is_history|热门酒店:0\thomepage");
                        }
					}
				} 
			});
            $("#J_popup_city").show();
            $("#J_sea_box").hide();
        }else{
            $("#J_popup_city").hide();
            $("#J_sea_box").show();
        }
    }).click(function(e){
        e.stopPropagation();
        $(this).select();
    }).keydown(function(e){
        if (e.keyCode == 38) {
            e.preventDefault();
        }
    }).keyup(function(e){
    	var obj_current = $('#J_sea_box .ser-row .ser-m-con .ser-li.ser-li-current');
        resetSearchTypeIcon('');
        var val = $(this).val();
		$(this).css({color : "#333"});
		urlencode_val = encodeURIComponent(val);
		urlencode_val = urlencode_val.replace('*', '%2A');
		$("#J_from").attr("action", "cz_"+ urlencode_val);
		config.search_type = "keywords|";
		if(is_sea_val != 0 && $("#J_sea_box").css("display") != "none" && sea_word != ""){
			// 向上
            if (e.keyCode == 38) {
                if (!obj_current.html()) {
                    var ser_row_nums = $('#J_sea_box .ser-row').length;
                    var end_ser_li_nums = $('#J_sea_box .ser-row:eq(' + ser_row_nums + ') .ser-m-con .ser-li').length;
                    obj_current = $('#J_sea_box .ser-row:eq(' + ser_row_nums + ') .ser-m-con .ser-li:eq(' + end_ser_li_nums + ')');
                    obj_current.addClass('ser-li-current');
                } else {
                    var this_el_index = obj_current.index();
                    if ((this_el_index - 1) >= 0) {
                        obj_current = obj_current.removeClass('ser-li-current').prev().addClass('ser-li-current');
                    } else {
                        if (obj_current.parents('.ser-row').prev().hasClass('ser-row')) {
                            obj_current = obj_current.removeClass('ser-li-current').parents('.ser-row').prev().find(".ser-m-con .ser-li:last").addClass('ser-li-current');
                        }
                    }
                }
                var em_html = obj_current.html();
                obj_current.find('.ser-m-con-right').remove();
                if(obj_current.attr("data-real-type") && obj_current.attr("data-real-type") === "island") {
                    resetSearchTypeIcon('island');
                }else{
                    resetSearchTypeIcon(obj_current.attr("data-type"));
                }
                var _html = obj_current.text();
                obj_current.html(em_html);
                //$("#J_city").val(_html);
                return false;
            }
			// 向下
            if (e.keyCode == 40) {
                if (!obj_current.html()) {
                    obj_current = $("#J_sea_box .ser-row:eq(0) .ser-m-con .ser-li:eq(0)").addClass('ser-li-current');
                } else {
                    var this_el_nums = obj_current.parents('.ser-m-con').find('.ser-li').length;
                    var this_el_index = obj_current.index() + 1;
                    if ((this_el_index + 1) <= this_el_nums) {
                        obj_current = obj_current.removeClass('ser-li-current').next().addClass('ser-li-current');
                    } else {
                        if (obj_current.parents('.ser-row').next().hasClass('ser-row')) {
                            obj_current = obj_current.removeClass('ser-li-current').parents('.ser-row').next().find(".ser-m-con .ser-li:eq(0)").addClass('ser-li-current');
                        }
                    }
                }
                var em_html = obj_current.html();
                obj_current.find('.ser-m-con-right').remove();
                if(typeof(obj_current.attr("data-real-type"))!="undefined" && obj_current.attr("data-real-type") === "island") {
                    resetSearchTypeIcon('island');
                }else{
                    resetSearchTypeIcon(obj_current.attr("data-type"));
                }
                var _html = obj_current.text();
                obj_current.html(em_html);
                //$("#J_city").val(_html);
                return false;
            }
			if(e.keyCode == 13){
				var chkin = $("#from").val();
				var chkout = $("#to").val();
				var room = $('#J_sel_room_num').val();
				var adult = $('#J_sel_room_adult').val();
				var child = $('#J_sel_room_child').val();
				var child_age = $('#J_sel_room_child_age').val();
				/*if(key_index == -1){
					var select_index = 0;
				}else{
					var select_index = key_index;
				}*/
				var li_obj = obj_current;
				var type = li_obj.attr("data-type");
				var data_name = li_obj.attr("data-name");
				var data_id = li_obj.attr("data-id");
				if(type == "poi"){
					poi_channel = "|"+li_obj.attr("data-channel");
				}
				if(type == undefined){
					type = 'keywords';
					data_name = $("#J_city").val();
					data_id = 0;
				}
				//alert(poi_channel);
				var current_index = li_obj.index();
                var current_conp_index = li_obj.parents('.ser-row').index();
                var iter_index = 1,total_sl_len = 0;
                $('#J_sea_box .ser-row').each(function(){
                    var sl_len = $(this).find('.ser-m-con .ser-li').length;
                    if (iter_index == current_conp_index) {
                        current_index += total_sl_len;
                    }
                    total_sl_len += sl_len;
                    ++iter_index;
                });
				tj && tj.sea_click("select|"+ data_name +"\thomepage\t"+config.dist_id+"|"+config.user_id+"|"+chkin+"|"+chkout+"|"+room+"|"+adult+"|"+child+"|"+"|"+child_age+"|\t"+$("#J_city").val()+"\t"+type+poi_channel+"|"+data_id+"\t"+current_index+"|"+total_sl_len);
				li_obj.find('.ser-m-con-right').remove();
				$("#J_city").val(li_obj.text()).css({color : "#333"}).removeClass("index-date-error");
				if(li_obj.attr("data-real-type") && li_obj.attr("data-real-type") === "island") {
                    resetSearchTypeIcon('island');
                }else{
                    resetSearchTypeIcon(li_obj.attr("data-type"));
				}
				$("#J_city_hid").val(li_obj.attr("data-cityid"));
				$("#J_sea_box").hide();
				var id = li_obj.attr("data-id");
				var type = li_obj.attr("data-type");
				var city_id = li_obj.attr("data-cityid");
				var urlname = li_obj.attr("data-urlname");
				var is_alias = li_obj.attr("data-alias");
				if(is_alias == 1){
					$("#J_alias").val(li_obj.attr("data-name")).attr("name", "alias");
				}else{
					$("#J_alias").attr("name", "");;
				}
                config.search_data = type;
				if(type == "country"){
					$("#J_from").attr("action", urlname +".html");
                    config.search_data = config.search_data + "|"  + id;
				}else if(type == "region"){
					$("#J_from").attr("action", urlname +".html");
                    config.search_data = config.search_data + "|" + id;
				}else if(type == "city"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/");
                    config.search_data = config.search_data + "|" + id;
				}else if(type == "area"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/a"+ id);
                    config.search_data = config.search_data + "|" + city_id + "|" +id;
				}else if(type == "hotel"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/"+ id +".html");
                    config.search_data = config.search_data + "|" + city_id + "|" +id;
				}else if(type == "attr"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/attr"+ id);
                    config.search_data = config.search_data + "|" + city_id + "|" +id;
				}else if(type == "poi"){
					var lat = li_obj.attr("data-lat");
					var lan = li_obj.attr("data-lan");
					var dataname = li_obj.attr("data-name");
					$("#J_lat").val(lat);
					$("#J_lan").val(lan);
					$("#J_type").val(type);
					$("#J_name").val(dataname);
					$("#J_from").attr("action",urlname +"_c"+ city_id );
					config.search_type = config.search_type + "|" + city_id;
                    config.search_data = config.search_data + poi_channel + "|" + city_id;
				}
                config.urlname = urlname;
				$("#J_tips").hide();
				is_sea_val = 0;
				return false;
			}
		}
        stamp = (new Date()).valueOf();
        req_search_num = 1;
        search(val);

		/*if(val.length >3 && tmp_ajax != ""){
			tmp_ajax.abort();
		}*/

    }).bind('paste', function(e) {
        var el = $(this);
        setTimeout(function() {
            var val = el.val();

            $(this).css({color : "#333"});

            urlencode_val = encodeURIComponent(val);
            urlencode_val = urlencode_val.replace('*', '%2A');

            $("#J_from").attr("action", "cz_"+ urlencode_val);

            if(is_sea_val != 0 && $("#J_sea_box").css("display") != "none" && sea_word != ""){
            	var obj_current = $('#J_sea_box .ser-row .ser-m-con .ser-li.ser-li-current');
                var li_obj = obj_current;

                if(e.keyCode == 38){
                    if (!obj_current.html()) {
                        var ser_row_nums = $('#J_sea_box .ser-row').length;
                        var end_ser_li_nums = $('#J_sea_box .ser-row:eq(' + ser_row_nums + ') .ser-m-con .ser-li').length;
                        obj_current = $('#J_sea_box .ser-row:eq(' + ser_row_nums + ') .ser-m-con .ser-li:eq(' + end_ser_li_nums + ')');
                        obj_current.addClass('ser-li-current');
                    } else {
                        var this_el_index = obj_current.index();
                        if ((this_el_index - 1) >= 0) {
                            obj_current = obj_current.removeClass('ser-li-current').prev().addClass('ser-li-current');
                        } else {
                            if (obj_current.parents('.ser-row').prev().hasClass('ser-row')) {
                                obj_current = obj_current.removeClass('ser-li-current').parents('.ser-row').prev().find(".ser-m-con .ser-li:last").addClass('ser-li-current');
                            }
                        }
                    }
                    var em_html = obj_current.html();
                    obj_current.find('.ser-m-con-right').remove();
                    if(obj_current.attr("data-real-type") && obj_current.attr("data-real-type") === "island") {
                        resetSearchTypeIcon('island');
                    }else{
                        resetSearchTypeIcon(obj_current.attr("data-type"));
                    }
                    var _html = obj_current.text();
                    obj_current.html(em_html);
                    //$("#J_city").val(_html);
                    return false;
                }
                if(e.keyCode == 40){
                    if (!obj_current.html()) {
                        obj_current = $("#J_sea_box .ser-row:eq(0) .ser-m-con .ser-li:eq(0)").addClass('ser-li-current');
                    } else {
                        var this_el_nums = obj_current.parents('.ser-m-con').find('.ser-li').length;
                        var this_el_index = obj_current.index() + 1;
                        if ((this_el_index + 1) <= this_el_nums) {
                            obj_current = obj_current.removeClass('ser-li-current').next().addClass('ser-li-current');
                        } else {
                            if (obj_current.parents('.ser-row').next().hasClass('ser-row')) {
                                obj_current = obj_current.removeClass('ser-li-current').parents('.ser-row').next().find(".ser-m-con .ser-li:eq(0)").addClass('ser-li-current');
                            }
                        }
                    }
                    var em_html = obj_current.html();
                    obj_current.find('.ser-m-con-right').remove();
                    if(obj_current.attr("data-real-type") && obj_current.attr("data-real-type") === "island") {
                        resetSearchTypeIcon('island');
                    }else{
                        resetSearchTypeIcon(obj_current.attr("data-type"));
                    }
                    var _html = obj_current.text();
                    obj_current.html(em_html);
                    //$("#J_city").val(_html);
                    return false;
                }
                if(e.keyCode == 13){
					var chkin = $("#from").val();
					var chkout = $("#to").val();
					var room = $('#J_sel_room_num').val();
					var adult = $('#J_sel_room_adult').val();
					var child = $('#J_sel_room_child').val();
					var child_age = $('#J_sel_room_child_age').val();
					
					/*if(key_index == -1){
						var select_index = 0;
					}else{
						var select_index = key_index;
					}*/
					var type = li_obj.attr("data-type");
					var data_name = li_obj.attr("data-name");
					var data_id = li_obj.attr("data-id");
					if(type == "poi"){
						poi_channel = "|"+li_obj.attr("data-channel");
					}
					if(type == undefined){
						type = 'keywords';
						data_name = $("#J_city").val();
						data_id = 0;
					}
					var current_index = li_obj.index();
                    var current_conp_index = li_obj.parents('.ser-row').index();
                    var iter_index = 1,total_sl_len = 0;
                    $('#J_sea_box .ser-row').each(function(){
                        var sl_len = $(this).find('.ser-m-con .ser-li').length;
                        if (iter_index == current_conp_index) {
                            current_index += total_sl_len;
                        }
                        total_sl_len += sl_len;
                        ++iter_index;
                    });
					tj && tj.sea_click("select|"+ data_name +"\thomepage\t"+config.dist_id+"|"+config.user_id+"|"+chkin+"|"+chkout+"|"+room+"|"+adult+"|"+child+"|"+"|"+child_age+"|\t"+$("#J_city").val()+"\t"+type+poi_channel+"|"+data_id+"\t"+current_index+"|"+total_sl_len);
					li_obj.find('.ser-m-con-right').remove();
					$("#J_city").val(li_obj.text()).css({color : "#333"}).removeClass("index-date-error");
					if(li_obj.attr("data-real-type") && li_obj.attr("data-real-type") === "island") {
                        resetSearchTypeIcon('island');
					}else{
                        resetSearchTypeIcon(li_obj.attr("data-type"));
					}
					$("#J_city_hid").val(li_obj.attr("data-cityid"));
					$("#J_sea_box").hide();

					var id = li_obj.attr("data-id");
					var type = li_obj.attr("data-type");
					var city_id = li_obj.attr("data-cityid");
					var urlname = li_obj.attr("data-urlname");
					var is_alias = li_obj.attr("data-alias");

					if(is_alias == 1){
						$("#J_alias").val(li_obj.attr("data-name")).attr("name", "alias");
					}else{
						$("#J_alias").attr("name", "");
					}
                    config.search_data = type;
                    if(type == "country"){
                        $("#J_from").attr("action", urlname +".html");
                        config.search_data = config.search_data + "|"  + id;
                    }else if(type == "region"){
                        $("#J_from").attr("action", urlname +".html");
                        config.search_data = config.search_data + "|" + id;
                    }else if(type == "city"){
                        $("#J_from").attr("action", urlname +"_c"+ city_id +"/");
                        config.search_data = config.search_data + "|" + id;
                    }else if(type == "area"){
                        $("#J_from").attr("action", urlname +"_c"+ city_id +"/a"+ id);
                        config.search_data = config.search_data + "|" + city_id + "|" +id;
                    }else if(type == "hotel"){
                        $("#J_from").attr("action", urlname +"_c"+ city_id +"/"+ id +".html");
                        config.search_data = config.search_data + "|" + city_id + "|" +id;
                    }else if(type == "attr"){
                        $("#J_from").attr("action", urlname +"_c"+ city_id +"/attr"+ id);
                        config.search_data = config.search_data + "|" + city_id + "|" +id;
                    }else if(type == "poi"){
						var lat = li_obj.attr("data-lat");
						var lan = li_obj.attr("data-lan");
						var dataname = li_obj.attr("data-name");
						poi_channel = "|"+li_obj.attr("data-channel");
						$("#J_lat").val(lat);
						$("#J_lan").val(lan);
						$("#J_type").val(type);
						$("#J_name").val(dataname);
						$("#J_from").attr("action",urlname +"_c"+ city_id );
						config.search_type = config.search_type + "|" + city_id;
                        config.search_data = config.search_data + poi_channel + "|" + city_id;
					}
                    config.urlname = urlname;
					
					$("#J_tips").hide();
					is_sea_val = 0;
					return false;
                }
            }
			search_is_complete = 0;
            restartflag = 0;
            stamp = (new Date()).valueOf();
            req_search_num = 1;
            search(val);
        }, 100);

    });

	var sea_timer = false;
	var restartflag = 0;
	var search_is_complete = 0;
	var search_ajax_start = 0;
    var stamp = (new Date()).valueOf();
    var stamp_back = (new Date()).valueOf();
	//搜索框检索
    var req_search_num = 1;
	function search(val){
		if(val.replace(/\s*/g, "") != ""){
			if((is_ajax == 1 || val == sea_word) && search_is_complete){
                req_search_num++;
				return false;
			}
			//poi is_complete = false request(s)
			if(val==sea_word){
				if(restartflag==1){
					var search_ajax_now = Date.parse(new Date());
					var cha = parseInt(search_ajax_now - search_ajax_start);
					if(cha > 5000){
						search_is_complete =1;
                        restartflag=0;
                        req_search_num = 1;
						return false;
					}
				}
			}
			key_index = -1;
			sea_word = val;
			is_sea_val = 1;
			$("#J_city_hid").val("");
			$("#J_city").css({color : "#333"});
			is_ajax = 1;
			sea_timer && clearTimeout(sea_timer);
			tmp_ajax = HQ.ajax("/ajax/search_v1", {keyword:val, type:"homepage", stamp:stamp, req_search_num:req_search_num}, function(data){
                req_search_num++;
				$("#J_popup_city").hide();
				$("#J_sea_box").show();
				$(".J_room_sel_win").hide();
				var html = '<div class="index-ser-top-title">'+HQ.config.language.list_tips[language][1]+'</div>';
				if(data.msg == 0 || data.res == ""){
					html += '<div class="no-res" style="padding: 6px 66px 6px 10px;background: #fff;color: #c00;cursor: default;background: none;">'+HQ.config.language.list_tips[language][2]+'</div>';
                    if(data.stamp>=stamp_back) {
                        if(data.req_search_num <= 1){
                            $("#J_sea_box").html(html);
                        }
                    }
				}else{
                    if(data.stamp>=stamp_back){
                        if(data.req_search_num <= 1){
                            $("#J_sea_box").html(data.res);
                        }else{
                            $("#J_sea_box").find(".ser-poi").remove();
                            $("#J_sea_box").find(".ser-row-bot").before(data.res);
                        }
                        // 选中第一个搜索项
                        $("#J_sea_box .ser-row:eq(0) .ser-m-con .ser-li:eq(0)").addClass("ser-li-current");
                        stamp_back = data.stamp;
                    }
				}
				search_is_complete = data.is_complete;
				if(search_is_complete){
					restartflag = 0;
				}
				if(restartflag==0 && !search_is_complete && val==sea_word){
					search_ajax_start = Date.parse(new Date());
					restartflag = 1;
				}
				sea_timer = setTimeout(function(){
					if($("#J_city").val() != sea_word || (!search_is_complete && restartflag==1)){
                        if($("#J_city").val() != sea_word){
                            req_search_num = 1;
                        }
                        stamp = (new Date()).valueOf();
						search($("#J_city").val());
					}
				}, 300);
				is_ajax = 0;
			});
		}else{
			$.ajax({ 
				type:"post", 
				url:"/ajax/get_search_recommend_hotel_v1", 
				data: {}, 
				dataType: 'json', 
				async : false,
				success:function(data){ 
					if(data.res == 0){
                        // 最近浏览recent_se_html
                        var is_history_show = false;
                        if(data.msg.history_html != ''){
                            $("#J_popup_city .se-history-list").html(data.msg.history_html).parents(".se-row").show();
                            $("#J_popup_city .index-se-con-recent").show();
                            tj && tj.sea_click("is_history|热门酒店:1\thomepage");
                            is_history_show = true;
                        }else{
                            $("#J_popup_city .se-history-list").parents(".se-row").hide();
                            tj && tj.sea_click("is_history|热门酒店:0\thomepage");
                        }
                        // 常订酒店
                        if(data.msg.frequently_html != ''){
                            $("#J_popup_city .se-frequently-hotel-list").html(data.msg.frequently_html).parents(".se-row").show();
                            $("#J_popup_city .index-se-con-recent").show();
                            tj && tj.sea_click("is_frequently|热门酒店:1\thomepage");
                            if (is_history_show) {
                                $("#J_popup_city .se-frequently-hotel-list").parents(".se-row").addClass('m-t13');
                            } else {
                                $("#J_popup_city .se-frequently-hotel-list").parents(".se-row").removeClass('m-t13');
                            }
                        }else{
                            $("#J_popup_city .se-frequently-hotel-list").parents(".se-row").hide();
                            tj && tj.sea_click("is_frequently|热门酒店:0\thomepage");
                        }
                        // 推荐城市
                        if(data.msg.recommend_city_html != ''){
                            $("#J_popup_city .se-recommend-hot-list").html(data.msg.recommend_city_html);
                        }
                        // 最近浏览
                        if(data.msg.recent_se_html != ''){
                            $("#J_popup_city .se-recently-se-list").html(data.msg.recent_se_html).parents(".se-row").show();
                            // tj && tj.sea_click("is_history|热门酒店:1\thomepage");
                        }else{
                            $("#J_popup_city .se-recently-se-list").parents(".se-row").hide();
                            // tj && tj.sea_click("is_history|热门酒店:0\thomepage");
                        }
					}
				} 
			}); 
			
			$("#J_sea_box").hide().html("");
			$("#J_city").css({color : "#ddd"});
			$("#J_popup_city").show();
			is_sea_val = 0;
			sea_word = "";
		}
	}

    //查找酒店
    $("#J_search_hotel").click(function(){
        if($("#J_sea_box li").eq(0).attr("data-nores") == 1){
            $("#J_city").focus();

            return false;
        }
        if (!search_citizenship || !search_citizenship_name) {
            $('.J_sel_num_citizenship').addClass("index-date-error")
            return
        }
        sea_hotel();
        return false;
    });
    function sea_hotel(){
        if($("#J_city").val().replace(/\s/g, "") == "" || $("#J_city").val() == $("#J_city").attr("data-placeholder")){
            $("#J_city").focus().addClass("index-date-error");
            return false;
        }
        if($("#from").val() == "" || $("#from").val() == $("#from").attr("data-placeholder")){
            $("#from").focus().parent().addClass("index-date-error");
            from.datepicker("show");
            return false;
        }else if($("#to").val() == "" || $("#to").val() == $("#to").attr("data-placeholder")){
            $("#to").focus().parent().addClass("index-date-error");
            to.datepicker("show");
            return false;
        }
		
		if(!$("#J_sea_box").is(":hidden")){
			var li_obj = $("#J_sea_box .ser-row .ser-m-con .ser-li");
			if(li_obj.attr("data-nores") != 1){
				li_obj.eq(0).find('.ser-m-con-right').remove();
				$("#J_city").val(li_obj.eq(0).text()).css({color : "#333"}).parent().removeClass("index-date-error");
				if(li_obj.eq(0).attr("data-real-type") && li_obj.eq(0).attr("data-real-type") === "island") {
                    resetSearchTypeIcon('island');
				}else{
                    resetSearchTypeIcon(li_obj.eq(0).attr("data-type"));
				}
				$("#J_city_hid").val(li_obj.eq(0).attr("data-cityid"));
				$("#J_sea_box").hide();

				var id = li_obj.eq(0).attr("data-id");
				var type = li_obj.eq(0).attr("data-type");
				var city_id = li_obj.eq(0).attr("data-cityid");
				var urlname = li_obj.eq(0).attr("data-urlname");
				var is_alias = li_obj.eq(0).attr("data-alias");

				if(is_alias == 1){
					$("#J_alias").val(li_obj.eq(0).attr("data-name")).attr("name", "alias");
				}else{
					$("#J_alias").attr("name", "");;
				}
				
				if(type == "country"){
					$("#J_from").attr("action", urlname +".html");
				}else if(type == "region"){
					$("#J_from").attr("action", urlname +".html");
				}else if(type == "city"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/");
				}else if(type == "area"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/a"+ id);
				}else if(type == "hotel"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/"+ id +".html");
				}else if(type == "attr"){
					$("#J_from").attr("action", urlname +"_c"+ city_id +"/attr"+ id);
				} else if(type == "poi"){
					var lat = li_obj.eq(0).attr("data-lat");
					var lan = li_obj.eq(0).attr("data-lan");
					var dataname = li_obj.eq(0).attr("data-name");
					poi_channel = "|"+li_obj.eq(0).attr("data-channel");
					$("#J_lat").val(lat);
					$("#J_lan").val(lan);
					$("#J_type").val(type);
					$("#J_name").val(dataname);
					$("#J_from").attr("action",urlname +"_c"+ city_id );
				}

				$("#J_tips").hide();
				
				is_sea_val = 0;
			}

		}

        var chkin = $("#from").val();
        var chkout = $("#to").val();
        var room = $('#J_sel_room_num').val();
        if (!room || room == 'undefined') {
            room = 1
        }
        var adult = $('#J_sel_room_adult').val();
        if (!adult || adult == 'undefined') {
            adult = 2
        }
        var child = $('#J_sel_room_child').val();
        if (!child || child == 'undefined') {
            child = 0
        }
        var child_age = $('#J_sel_room_child_age').val();
        if (!child_age || child_age == 'undefined') {
            child_age = ''
        }
        var citizenship = search_citizenship;
        HQ.ajax("/ajax/set_date", {chkin : chkin, chkout : chkout,room_num:room,adult:adult,child:child,child_age:child_age,citizenship:citizenship});
		
		tj && tj.btn_click("inventory_search\t||"+config.dist_id+"|"+config.user_id+"|"+chkin+"|"+chkout+"|"+room+"|"+adult+"|"+child+"|"+"|"+child_age+"|\t1\thomepage\t"+$("#J_city").val()+"\t"+config.search_type);
        $("#J_from").submit();
    }
    //输入框获取失去焦点
    $("#J_date input").focus(function(){
        $(this).parent().addClass("index-date-current");
    }).blur(function(){
        $(this).parent().removeClass("index-date-current");
        var _this = $(this);
        var timer = setTimeout(function(){
            if(_this.val() != ""){
                _this.parent().removeClass("index-date-error");
            }
        }, 10);
    });

    //vue
    var _v;
    var vueModel = {
        el: '#J_from',
        data: {
            cityList: [],
            cityShow: false,
            cityName: '',
            cityId: '',
            props: {
                value: 'id',
                label: 'title',
                children: '_child'
            }
        },
        methods: {
            changeArea: function(v) {
                console.log(v)
            },
            fetchData: function () {
                HQ.getArea2(function(data) {
                    _v.cityList = data;
                })
            },
            initDatePicker: function () {
                //日期
                var date = "";
                var dateFormat ="";
                if (language == 'zh-CN'){
                    dateFormat = "yy-mm-dd";
                }else{
                    dateFormat = "M-dd-yy";
                }
                var max_date = new Date(new Date().getTime() + 365 * 24 * 60 * 60 * 1000);
                console.log(HQ.config.language.short_week[language]);
                console.log(week);
                console.log(config.month);
                console.log(config.monthShort);
                var from = $("#from").datepicker({
                    dateFormat : dateFormat,
                    dayNames : HQ.config.language.short_week[language],
                    altField: "#from_week",
                    altFormat : "DD",
                    minDate : new Date(),
                    maxDate : max_date,
                    to : "to",
                    numberOfMonths: 2,
                    dayNamesMin: week,
                    monthNames: config.month,
                    monthNamesShort:config.monthShort,
                    showAnim : "",
                    beforeShow: function(input) {
                        $(".sanjiao").css('display','block');
                        $(this).addClass('select_on');
                    },
                    onSelect : function(selectedDate){
                        selectedDate = format_date_en(selectedDate);
                        var time = selectedDate.split("-");
                        var time1 = [];
                        $("#to").datepicker( "option", "minDate", selectedDate);
                        time1[0] = time[0];
                        time1[1] = time[1] - 1;
                        time1[2] = time[2];
                        if(time[1] == 12){
                            time[0] = parseInt(time[0])+1;
                            time[1] = 0;
                            if(time[2] == 31){
                                time1[2] = 1;
                                time1[1] = 0;
                                time1[0] = time[0];
                            }else{
                                time1[2] = parseInt(time[2]) + 1;
                            }
                        }else{
                            time1[2] = parseInt(time[2]) + 1;
                        }
                        if(time[2] > 28){
                            time[2] = 28;
                        }

                        $("#from").css({color : "#333"});
                        $("#to").css({color : "#333"});
                        $("#from_week").css({color : "#999"});
                        $("#to_week").css({color : "#999"});

                        if (language == 'zh-CN'){
                            $("#to").val(time1[0] +"-"+ (parseInt(time1[1])+1) +"-"+ time1[2]);
                        }else{
                            $("#to").val(config.monthShort[parseInt(time1[1])] +"-"+ time1[2] +"-"+ time1[0]);
                        }

                        $("#to").datepicker( "option", "minDate", new Date(time1[0], time1[1], time1[2]));
                        $("#to").datepicker( "option", "maxDate", new Date(time[0], time[1], time[2]));
                        $(this).removeClass('select_on');
                        setTimeout(function(){
                            to.datepicker("show");
                        }, 10);

                    },
                    onClose : function( selectedDate ) {
                        $(this).removeClass('select_on');
                        $(".sanjiao").css('display','none');
                        $(".sanjiao2").css('display','none');
                    }
                });
                var min_de_date = new Date($("#from").val());
                var min_de_month = min_de_date.getMonth();
                var min_de_year = min_de_date.getFullYear();
                var max_de_month = parseInt(min_de_month) + 1;
                var max_de_year = min_de_year;
                if (max_de_month == 13) {
                    max_de_year = parseInt(min_de_year) + 1;
                }
                var max_de_date = new Date(max_de_year, max_de_month, min_de_date.getDate());
                var to = $("#to").datepicker({
                    dateFormat : dateFormat,
                    dayNames :  HQ.config.language.short_week[language],
                    altField: "#to_week",
                    altFormat : "DD",
                    minDate : min_de_date,
                    maxDate : max_de_date,
                    from : "from",
                    dateMouse : true,
                    numberOfMonths: 2,
                    dayNamesMin: week,
                    monthNames: config.month,
                    monthNamesShort: config.monthShort,
                    showAnim : "",
                    beforeShow: function(input) {
                        $(this).addClass('select_on');
                        $(".sanjiao").css('display','none');
                        $(".sanjiao2").css('display','block');
                    },
                    onSelect : function(selectedDate){
                        var starTime = $("#from").val();
                        var endTime = selectedDate;
                        var TimeDiff = datedifference(starTime,selectedDate);
                        var lang_night =HQ.config.language.common[language][14];
                        var lang_nights =HQ.config.language.common[language][15];
                        if (TimeDiff >1){
                            TimeDiff = TimeDiff +lang_nights;
                        }else{
                            TimeDiff = TimeDiff +lang_night;
                        }

                        $("#dayNight").html(TimeDiff);
                        $(this).removeClass('select_on');
                    },
                    onClose : function( selectedDate ) {
                        $(this).removeClass('select_on');
                        $(".sanjiao").css('display','none');
                        $(".sanjiao2").css('display','none');
                    }
                });

                $('#from').val(moment().format('YYYY-MM-DD'));
                $('#to').val(moment().add(1, 'd').format('YYYY-MM-DD'));
            },
            searchList: function () {
                if (!$('#from').val() || !$('#to').val()) {
                    alert('请选择日期');
                    return;
                }
                location.href = '/list.html?'+ 'city_id='+ _v.cityId + '&key_words='+ _v.cityName + '&date_start='+ $('#from').val() + '&date_end='+ $('#to').val()
            }
        },
        mounted: function () {
            _v = this;
            _v.fetchData();
            _v.initDatePicker();
            if (!!localStorage.getItem('_token')) {
                var nickname = JSON.parse(localStorage.getItem('_token') || '{}').nick_name;
                $('.nav-nickname-btn').text(nickname).show();
                $('.nav-register-btn').hide();
            } else {
                $('.nav-register-btn').show();
                $('.nav-nickname-btn').hide();
            }
        }
    }
    vueInstan = new Vue(vueModel);

	//计算天数差的函数，通用
	function datedifference(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式
		var dateSpan,
			tempDate,
			iDays;
		var Sa_date1 = new Date(Date.parse(new Date(sDate1.replace(/-/g,"/"))));
		var Sa_date2 = new Date(Date.parse(new Date(sDate2.replace(/-/g,"/"))));
		/*sDate1 = Date.parse(sDate1);
		 sDate2 = Date.parse(sDate2);*/
		dateSpan = Sa_date2 - Sa_date1;
		dateSpan = Math.abs(dateSpan);
		iDays = Math.floor(dateSpan / (24 * 3600 * 1000));

		return iDays
	};
    $("#from_week").click(function(){

        event.stopPropagation();
    });

    //支持placeholder
    var isInputSupported = 'placeholder' in document.createElement('input');
    if(true){
        $("#J_date input").each(function(){
            if($(this).val() == ""){
                $(this).val($(this).attr("data-placeholder"));
            }
        });
        $("#J_date input").focus(function(){
            if($(this).val() == $(this).attr("data-placeholder")){
                $(this).val("");
            }
        }).blur(function(){
            if($(this).val() == ""){
                $(this).val($(this).attr("data-placeholder"));
            }
        });
        if($("#J_city").val() == ""){
            $("#J_city").val($("#J_city").attr("data-placeholder")).css("color","#999");
        }
        $("#J_city").focus(function(){
            if($(this).val() == $(this).attr("data-placeholder")){
                $(this).val("");
            }
        }).blur(function(){
            if($(this).val() == ""){
                $(this).val($(this).attr("data-placeholder")).css("color","#999");
            }
        });
    }
    //城市选择tab
    $("#J_city_tab li").click(function(e){
        var index = $("#J_city_tab li").index(this);
        $(".J_city_sel").hide().eq(index).show();
        $(this).addClass("current").siblings().removeClass("current");
        e.stopPropagation();
    });

    $("body").click(function(){
        $("#J_popup_city").hide();
        $('.J_room_sel_win_nationality').hide();
        $('.J_sel_num_citizenship').attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J_sel_num").attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J-room-pro").attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $('.J_clear_search_history_dialog').fadeOut('slow');

        if(!$("#J_sea_box").is(":hidden")){
			var li_obj = $("#J_sea_box .ser-row .ser-m-con .ser-li");
			if(li_obj.html()){
				li_obj.eq(0).find('.ser-m-con-right').remove();
				$("#J_city").val(li_obj.eq(0).text()).css({color : "#333"}).parent().removeClass("index-date-error");
				if(li_obj.eq(0).attr("data-real-type") && li_obj.eq(0).attr("data-real-type") === "island") {
                    resetSearchTypeIcon('island');
				}else{
                    resetSearchTypeIcon(li_obj.eq(0).attr("data-type"));
				}
				$("#J_city_hid").val(li_obj.eq(0).attr("data-cityid"));
				$("#J_sea_box").hide();

				var id = li_obj.eq(0).attr("data-id");
				var type = li_obj.eq(0).attr("data-type");
				var city_id = li_obj.eq(0).attr("data-cityid");
				var urlname = li_obj.eq(0).attr("data-urlname");
				var is_alias = li_obj.eq(0).attr("data-alias");

				if(is_alias == 1){
					$("#J_alias").val(li_obj.eq(0).attr("data-name")).attr("name", "alias");
				}else{
					$("#J_alias").attr("name", "");;
				}
                config.search_data = type;
                if(type == "country"){
                    $("#J_from").attr("action", urlname +".html");
                    config.search_data = config.search_data + "|"  + id;
                }else if(type == "region"){
                    $("#J_from").attr("action", urlname +".html");
                    config.search_data = config.search_data + "|" + id;
                }else if(type == "city"){
                    $("#J_from").attr("action", urlname +"_c"+ city_id +"/");
                    config.search_data = config.search_data + "|" + id;
                }else if(type == "area"){
                    $("#J_from").attr("action", urlname +"_c"+ city_id +"/a"+ id);
                    config.search_data = config.search_data + "|" + city_id + "|" +id;
                }else if(type == "hotel"){
                    $("#J_from").attr("action", urlname +"_c"+ city_id +"/"+ id +".html");
                    config.search_data = config.search_data + "|" + city_id + "|" +id;
                }else if(type == "attr"){
                    $("#J_from").attr("action", urlname +"_c"+ city_id +"/attr"+ id);
                    config.search_data = config.search_data + "|" + city_id + "|" +id;
                }else if(type == "poi"){
                    var lat = li_obj.eq(0).attr("data-lat");
                    var lan = li_obj.eq(0).attr("data-lan");
                    var dataname = li_obj.eq(0).attr("data-name");
                    poi_channel = "|"+li_obj.eq(0).attr("data-channel");
                    $("#J_lat").val(lat);
                    $("#J_lan").val(lan);
                    $("#J_type").val(type);
                    $("#J_name").val(dataname);
                    $("#J_from").attr("action",urlname +"_c"+ city_id );
                    config.search_type = config.search_type + "|" + city_id;
                    config.search_data = config.search_data + poi_channel + "|" + city_id;
                }
                config.urlname = urlname;
				$("#J_tips").hide();

				var chkin = $("#from").val();
				var chkout = $("#to").val();
				var room = $('#J_sel_room_num').val();
				var adult = $('#J_sel_room_adult').val();
				var child = $('#J_sel_room_child').val();
				var child_age = $('#J_sel_room_child_age').val();

				var total_sl_len = 0;
                $('#J_sea_box .ser-row').each(function(){
                    total_sl_len += $(this).find('.ser-m-con .ser-li').length;
                });
				
				tj && tj.sea_click("select|"+ li_obj.eq(0).attr("data-name") +"\thomepage\t"+config.dist_id+"|"+config.user_id+"|"+chkin+"|"+chkout+"|"+room+"|"+adult+"|"+child+"|"+"|"+child_age+"|\t"+$("#J_city").val()+"\t"+type+poi_channel+"|"+li_obj.eq(0).attr("data-id")+"\t1|"+total_sl_len);
				
				is_sea_val = 0;
			}

		}
        $("#J_sea_box").hide();
        $(".J_room_sel_win").hide();
        $(".J-room-pro").attr("data-isshow", 0);
        $('#J-more-normal-list').attr("data-isshow", 0);
        $('#J_more_option_num').attr("data-isshow", 0);
    });
    $('#J_more_option').click(function(){
        $(".J-room-pro").attr("data-isshow", 1);
        $('#J-more-normal-list').css("display","none");
        $('#J_more_option_num').css("display","block");
        $('#J-more-normal-list').attr("data-isshow", 0);
        $('#J_more_option_num').attr("data-isshow", 1);
        var J_peo_num_child = $('#J_peo_num_child'),
            childNum = parseInt(J_peo_num_child.attr('data-child')),
            childNum = parseInt($("#J_sel_room_child").val()),
            J_peo_num_html = $('#J_peo_num').html(),
            J_peo_num = parseInt(J_peo_num_html.replace(/.+\+ (\d).+/, '$1'));
        J_peo_num = childNum;
        J_peo_num_child.attr('data-child', childNum);
        $('.J_room_sel_win_peo_more_child a')[childNum].click();
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }

    });
    // 入住人数
    $('.d-room-person').click(function () {
        $('.J_room_sel_win_nationality').hide();
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
    })
    $('#J_more_option-normal').click(function(){
        $(".J-room-pro").attr("data-isshow", 1);
        $('#J-more-normal-list').css("display","block");
        $('#J_more_option_num').css("display","none");
        $('#J-more-normal-list').attr("data-isshow", 1);
        $('#J_more_option_num').attr("data-isshow", 0);
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
    });
    $(".J_sel_num_more_adult").click(function(){
        var is_show = $(this).attr("data-isshow");

        $(".J_sel_num_more_adult").attr("data-isshow", 0);
        $(this).parents('.J_room_sel_win_peo_more').find('div').attr('data-isshow',0);
        $(".J_room_sel_win_peo_more_adult").hide();

        if(is_show == 0){
            $(this).attr("data-isshow", 1);
            $(this).parents('.J_room_sel_win_peo_more').find('ul').hide();
            $(this).next().show();
        }
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }

        return false;
    });
    $(".J_sel_num_more_child").click(function(){
        var is_show = $(this).attr("data-isshow");

        $(".J_sel_num_more_child").attr("data-isshow", 0);
        $(this).parents('.J_room_sel_win_peo_more').find('div').attr('data-isshow',0);
        $(".J_room_sel_win_peo_more_child").hide();

        if(is_show == 0){
            $(this).attr("data-isshow", 1);
            $(this).parents('.J_room_sel_win_peo_more').find('ul').hide();
            $(this).next().show();
        }
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }

        return false;
    });
    $(".d-room-peo-child-age-list").on("click", ".J_sel_num_more_age", function(){
        var is_show = $(this).attr("data-isshow");

        $(this).attr("data-isshow", 0);
        $(this).parents('.J_room_sel_win_peo_more').find('div').attr('data-isshow',0);
        $(this).next(".J_room_sel_win_peo_more_age").hide();

        if(is_show == 0){
            $(this).attr("data-isshow", 1);
            $(this).parents('.J_room_sel_win_peo_more').find('ul').hide();
            $(this).next().show();
        }
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }

        return false;
    });
    $('.J_room_sel_win_peo_more').click(function(){
		var e=getEvent();
		if(window.event){
			e.cancelBubble=true;//阻止冒泡
		}else if(e.preventDefault){
			e.stopPropagation();//阻止冒泡
		}
	})
    $(".J_room_sel_win_peo_more_adult a").click(function(){
        sea_adult = $(this).attr("data-adult");
        $("#J_sel_room_adult").val($("#J_peo_num_adult").attr("data-adult"));

        $(".J_sel_num_more_adult").attr("data-isshow", 0);
        $(".J_room_sel_win_peo_more_adult").hide();

        $("#J_peo_num_adult").attr("data-adult", sea_adult).html($(this).html());
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
        return false;
    });
    $(".J_room_sel_win_peo_more_child a").click(function(){
        sea_child = $(this).attr("data-child");
        $("#J_sel_room_child").val($("#J_peo_num_child").attr("data-child"));

        $(".J_sel_num_more_child").attr("data-isshow", 0);
        $(".J_room_sel_win_peo_more_child").hide();

        $("#J_peo_num_child").attr("data-child", sea_child).html($(this).html());
        if (!config['child_age'] && typeof config['child_age'] === 'string') {
            config.child_age = [];
        }
        if(sea_child > 0) {
            $('.d-room-peo-child-age').show();
            var child_age_list = '';
            for(var i=0; i<sea_child; i++) {
                child_age_list += d_child_age_html;
                if(!config.child_age[i] || config.child_age.length < 1) {
                    config.child_age[i] = '1';
                }
                if (config.child_age[i] == '1') {
                    child_age_list = child_age_list.replace('{{child_age}}', '≤1');
                } else {
                    child_age_list = child_age_list.replace('{{child_age}}', config.child_age[i]);
                }
                child_age_list = child_age_list.replace('{{child_age_val}}', config.child_age[i]).replace('{{idx}}', i);
            }
            $('.d-room-peo-child-age-list').html(child_age_list);
        } else {
            $('.d-room-peo-child-age').hide();
            $('.d-room-peo-child-age-list').html('');
        }
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
        return false;
    });
    $(".d-room-peo-child-age-list").on("click", ".J_room_sel_win_peo_more_age a", function(){
        config.child_age[$(this).parents('.J_room_sel_win_peo_more_age').attr('data-idx')] = $(this).attr('data-val');
        var child_age_parents = $(this).parent().parent();
        var child_age_num = $(this).attr('data-val');
        child_age_parents.prev(".J_sel_num_more_age").attr("data-isshow", 0);
        child_age_parents.hide();
        child_age_parents.prev(".J_sel_num_more_age").children(".J_peo_num_age").attr('data-val', child_age_num).html($(this).html());
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
        return false;
    });

    $("#J-room-num-more-comfirm").click(function(){
        sea_adult = $("#J_peo_num_adult").attr("data-adult");
        sea_child = $("#J_peo_num_child").attr("data-child");
        sea_child_age = [];
        $(".d-room-peo-child-age-list").find('.J_peo_num_age').each(function(){
            sea_child_age.push($(this).attr('data-val'));
        });
        $("#J_sel_room_adult").val($("#J_peo_num_adult").attr("data-adult"));
        $("#J_sel_room_child").val($("#J_peo_num_child").attr("data-child"));
        $("#J_sel_room_child_age").val(sea_child_age.join(","));

        var adult_html = sea_adult+HQ.config.language.hotelRoom_tips[language][0];
        if(sea_adult > 1){
            adult_html = sea_adult+HQ.config.language.hotelRoom_tips[language][12];
        }
        var child_html = sea_child+HQ.config.language.search[language][1];
        if(sea_child > 1){
            child_html = sea_child+HQ.config.language.search[language][2];
        }
        $("#J_peo_num").html(adult_html+HQ.config.language.search[language][0]+child_html);

        $('.J-room-pro').attr('data-isshow', 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $('#J-more-normal-list').attr("data-isshow", 0);
        $("#J_more_option_num").attr("data-isshow", 1).hide();
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
    });
    $("#J-room-num-more-cancel").click(function(){
        $("#J_more_option_num").hide();
        $('#J-more-normal-list').attr('data-isshow', 0);
        $('.J-room-pro').attr('data-isshow', 0).children('.search-arrow-down').removeClass('search-arrow-up');
        var e=getEvent();
        if(window.event){
            e.cancelBubble=true;//阻止冒泡
        }else if(e.preventDefault){
            e.stopPropagation();//阻止冒泡
        }
    });

    $("#J_tj_tab span").click(function(){
        var _this = $(this);
        var index = $("#J_tj_tab span").index(this);
        var is_show = _this.attr("data-isshow");

        if(is_show == 1){
            $("#J_tj_tab span").removeClass("current");
            $(".J_tj_cont").hide();
            _this.attr("data-isshow", 0);
        }else{
            _this.addClass("current").siblings().removeClass("current").attr("data-isshow", 0);;
            $(".J_tj_cont").hide().eq(index).show();
            _this.attr("data-isshow", 1);
        }
    });

    $(".J_city_img").mouseenter(function(){
        $(this).addClass("current");
    }).mouseleave(function(){
        $(this).removeClass("current");
    });

    $("#J_city_img_sml li").mouseenter(function(){
        $(this).addClass("current");
    }).mouseleave(function(){
        $(this).removeClass("current");
    });

    var popup_index = "";
    $(".J_popup_city").click(function(){
        popup_index = $(this).attr("data-index");

        var poition = HQ.util.position.centerPosition($("#J_city_list"+ popup_index));
        $("#J_city_list"+ popup_index).css({left : poition.left, top : poition.top});
        $("#J_city_list"+ popup_index).fadeIn("slow");
        HQ.util.show_bg();

        return false;
    });
    $(".J_close_popup").click(function(){
        $(".index-popup").fadeOut("slow");
        $("#J_city_list"+ popup_index).fadeOut("slow");
        $("#bg").fadeOut("slow");

        return false;
    });

    $("#bg").click(function(){
        $(".index-popup").fadeOut("slow");
        $("#J_city_list"+ popup_index).fadeOut("slow");
        $("#bg").fadeOut("slow");
    });

    var hash = window.location.hash;
    if(/cid=/.test(hash)){
        var c_id = hash.replace(/#cid=(\d*?)/, "$1");

        HQ.ajax("/ajax/get_city_index", {
            cid : c_id
        }, function(data){
            if(typeof data.id != "undefined"){
                $("#J_city").val(data.cn_name);
                $("#J_from").attr("action", data.url_name +"_c"+ data.id +"/");
            }
        });
    }

    $("#J_popup_app_close").click(function(){
        $("#J_popup_app").show().stop().animate({
            opacity : 0,
            top : 60
        }, 300, function(){
            $(this).hide();
        });
        HQ.set_cookie("app_popup", "1", 15);
    });
    $(".J_sel_num").click(function(){
        $(".J_room_sel_win_peo").hide();
        $("#J_popup_city").hide();
        $("#J_sea_box").hide();
        $('.J_sel_num_citizenship').attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180')
        $(".J-room-pro").attr("data-isshow", 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        is_sea_val = 0;
        var _this = $(this),
            is_show = _this.attr("data-isshow");

        _this.attr("data-isshow", 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J_room_sel_win").hide();

        if(is_show == 0){
            _this.attr("data-isshow", 1);
            _this.next().show();
            _this.find('.icon-bottom-arrow-s').addClass('rotate-180');
        }
        return false;
    });
    $(".J_room_sel_win_room a").click(function(){
        $("#J_sel_room_num").val($(this).attr("data-val"));

        $(".J_sel_num").attr("data-isshow", 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J_room_sel_win").hide();

        $("#J_room_num").html($(this).html());

        return false;
    });
    $(".J-room-pro").click(function(){
        $("#J_popup_city").hide();
        $("#J_sea_box").hide();
        $(".J_room_sel_win_room").hide();
        is_sea_val = 0;
        var is_show = $(this).attr("data-isshow");
        $('#J_room_sel_win_nationality').hide();
        $(this).attr('data-isshow', 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J_sel_num").attr("data-isshow", 0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $('.J_sel_num_citizenship').attr("data-isshow",0).find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J_room_sel_win_peo").hide();
        $('.J_room_sel_win_peo_more').attr('data-isshow',0).hide();
        if(is_show == 0){
            $(this).attr("data-isshow", 1).find('.icon-bottom-arrow-s').addClass('rotate-180');
            if($('#J-more-normal-list').attr("data-isshow") == 1) {
                $('#J-more-normal-list').attr("data-isshow", 1).show();
            } else if($('#J_more_option_num').attr("data-isshow") == 1) {
                $('#J_more_option_num').attr("data-isshow", 1).show();
            } else {
                $('#J-more-normal-list').attr("data-isshow", 1).show();
            }
            var _sea_adult = $("#J_sel_room_adult").val();
            var _sea_child = $("#J_sel_room_child").val();
            if(_sea_adult > 4 || _sea_child > 0){
                $("#J_more_option").click();
            }
        }
        return false;
    });
    $(".J_room_sel_win_peo a").click(function(){
        sea_adult = $(this).attr("data-adult");
        sea_child = $(this).attr("data-child");
        $("#J_sel_room_adult").val($(this).attr("data-adult"));
        $("#J_sel_room_child").val($(this).attr("data-child"));
        sea_child_age = [];
        if(sea_child > 0){
            for(var i = 0; i < sea_child; i++){
                sea_child_age.push(10);
            }
        }
        $("#J_sel_room_child_age").val(sea_child_age.join(","));

        $(".J-room-pro").attr("data-isshow", 0);
        $(".J-room-pro").find('.icon-bottom-arrow-s').removeClass('rotate-180');
        $(".J_room_sel_win").hide();

        var adult_html = sea_adult+HQ.config.language.hotelRoom_tips[language][0];
        if(sea_adult > 1){
            adult_html = sea_adult+HQ.config.language.hotelRoom_tips[language][12];
        }
        var child_html = sea_child+HQ.config.language.search[language][1];
        if(sea_child > 1){
            child_html = sea_child+HQ.config.language.search[language][2];
        }
        $("#J_peo_num").html(adult_html+HQ.config.language.search[language][0]+child_html);
        $('#J-more-normal-list').attr("data-isshow", 1);
        $('#J_more_option_num').attr("data-isshow", 0);
        return false;
    });

    //event
    function getEvent(){
        if(window.event)    {return window.event;}
        func=getEvent.caller;
        while(func!=null){
            var arg0=func.arguments[0];
            if(arg0){
                if((arg0.constructor==Event || arg0.constructor ==MouseEvent
                    || arg0.constructor==KeyboardEvent)
                    ||(typeof(arg0)=="object" && arg0.preventDefault
                    && arg0.stopPropagation)){
                    return arg0;
                }
            }
            func=func.caller;
        }
        return null;
    }
    $(".index-myinfo-l-f-t").mouseover(function(){
        $(this).find(".index-myinfo-l-f-name").css("color","#49f");
    }).mouseout(function() {
        $(this).find(".index-myinfo-l-f-name").css("color", "#333");
    });

    //首页加入注册reg start
    //注册验证
    $("#J_company_name,#J_company_name_c").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][0]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_error_tips[language][2]).css('color','#333333');
        }
        if(val.length>50){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][1]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_error_tips[language][2]).css('color','#333333');
        }
        var reg=/^[%&.@#!',;=?$|￥*~_\d]*$/;
        if(reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][1]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_error_tips[language][2]).css('color','#333333');
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_contact_name,#J_contact_name_c").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][3]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
        var reg=/^[\u4E00-\u9FA5A-Za-z]{0,50}$/;
        if(!reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][4]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_contact_title").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][5]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
        if(val.length>50){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][6]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
        var reg=/^[%&.@#!',;=?$|￥\^*~_\d]*$/;
        if(reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_error_tips[language][7]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_contact_email").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_errorEmail_tips[language][0]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_errorEmail_tips[language][1]).css("color","#333333");
        }
        var reg=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
        if(!reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_errorEmail_tips[language][2]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_contact_email_c").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_errorEmail_tips[language][3]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_errorEmail_tips[language][4]).css("color","#333333");
        }
        var reg=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
        if(!reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_errorEmail_tips[language][5]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_contact_phone").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_errorPhone_tips[language][0]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_errorPhone_tips[language][1]).css("color","#333333");
        }
        var reg=/^[0-9-_\+]{7,20}$/;
        if(!reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_errorPhone_tips[language][2]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html(HQ.config.language.com_errorPhone_tips[language][1]).css("color","#333333");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_contact_qq").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next("span").html(HQ.config.language.com_errorqq_tips[language][0]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
        var reg=/^[0-9]{6,20}$/;
        if(!reg.test(val)){
            $(this).next("span").html(HQ.config.language.com_errorqq_tips[language][1]).css("color","#cc0000");
            return false;
        }else{
            $(this).next("span").html("");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_vcode,#J_vcode_c").blur(function(){
        var val = $(this).val();
        if(val.length==0){
            $(this).next().next("span").html(HQ.config.language.com_errorImgCode_tips[language][0]).css("color","#cc0000");
            return false;
        }else{
            $(this).next().next("span").html("");
        }
        var reg=/^[A-Za-z0-9]{0,4}$/;
        if(!reg.test(val)){
            $(this).next().next("span").html(HQ.config.language.com_errorImgCode_tips[language][1]).css("color","#cc0000");
            return false;
        }else{
            $(this).next().next("span").html("");
        }
    }).focus(function(){
        $("#J-reg-res").html("");
    });

    $("#J_send_email_c").click(function(){
        var email = $("#J_contact_email_c").val();


        if(email.length==0){
            $("#J_contact_email_c").next("span").html(HQ.config.language.com_errorEmail_tips[language][3]).css("color","#cc0000");
            return false;
        }else{
            $("#J_contact_email_c").next("span").html(HQ.config.language.com_errorEmail_tips[language][4]).css("color","#333333");
        }
        var reg=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
        if(!reg.test(email)){
            $("#J_contact_email_c").next("span").html(HQ.config.language.com_errorEmail_tips[language][5]).css("color","#cc0000");
            return false;
        }else{
            $("#J_contact_email_c").next("span").html("");
        }

        var vcode = $("#J_vcode_c").val();
        if(vcode.length==0){
            $("#J_vcode_c").next().next("span").html(HQ.config.language.com_errorImgCode_tips[language][0]).css("color","#cc0000");
            return false;
        }else{
            $("#J_vcode_c").next().next("span").html("");
        }
        var reg=/^[A-Za-z0-9]{0,4}$/;
        if(!reg.test(vcode)){
            $("#J_vcode_c").next().next("span").html(HQ.config.language.com_errorImgCode_tips[language][1]).css("color","#cc0000");
            return false;
        }else{
            $("#J_vcode_c").next().next("span").html("");
        }

        $("#J_send_email_c").next("span").html(HQ.config.language.com_errorSendEmail[language][0]).css("color","#cc0000");
        HQ.ajax("/register/send_mail/", {email:email,vcode:vcode}, function(data){
            if(data.state == 'y'){
                $("#"+data.errorid+" ~span").html(data.info).css("color","#cc0000");
                wait_time($("#J_send_email_c"),59,'r_m_',HQ.config.language.com_errorSendEmail[language][1]);
            } else {
                $("#J_send_email_c").next("span").html("");
                $("#"+data.errorid+" ~span").html(data.info).css("color","#cc0000");
                $("#J_verify_code_m_c").attr('src', '/verify_code?t='+(new Date().getTime()));
                return false;
            }
        }, function(){}, "POST");

    });

    $("#J_register_btn").click(function(){
        var J_company_name= $("#J_company_name").val();
        var J_contact_name= $("#J_contact_name").val();
        var J_contact_title= $("#J_contact_title").val();
        var J_contact_email= $("#J_contact_email").val();
        var J_contact_phone= $("#J_contact_phone").val();
        var J_contact_qq= $("#J_contact_qq").val();
        var J_vcode= $("#J_vcode").val();
        var J_type = 0;

        if(J_company_name.length==0){
            $("#J_company_name").next("span").html("请输入公司名称").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[%&.@#!',;=?$|￥\^*~_\d]*$/;
            if(reg.test(J_company_name)){
                $("#J_company_name").next("span").html("请输入真实的公司名称").css("color","#cc0000");
                return false;
            }
            if(J_company_name.length>50){
                $("#J_company_name").next("span").html("请输入真实的公司名称").css("color","#cc0000");
                return false;
            }
        }
        if(J_contact_name.length==0){
            $("#J_contact_name").next("span").html("请输入您的姓名").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[\u4E00-\u9FA5A-Za-z]{0,50}$/;
            if(!reg.test(J_contact_name)){
                $("#J_contact_name").next("span").html("请输入真实的姓名").css("color","#cc0000");
                return false;
            }
            if(J_contact_name.length>50){
                $("#J_contact_name").next("span").html("请输入真实的姓名").css("color","#cc0000");
                return false;
            }
        }
        if(J_contact_title.length==0){
            $("#J_contact_title").next("span").html("请输入您的职位").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[%&.@#!',;=?$|￥\^*~_\d]*$/;
            if(reg.test(J_contact_title)){
                $("#J_contact_title").next("span").html("请输入真实的职位").css("color","#cc0000");
                return false;
            }
            if(J_contact_title.length>50){
                $("#J_contact_title").next("span").html("请输入真实的职位").css("color","#cc0000");
                return false;
            }
        }
        if(J_contact_email.length==0){
            $("#J_contact_email").next("span").html("请输入联系邮箱").css("color","#cc0000");
            return false;
        }else{
            var reg=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
            if(!reg.test(J_contact_email)){
                $("#J_contact_email").next("span").html("请输入真实的联系邮箱").css("color","#cc0000");
                return false;
            }
        }
        if(J_contact_phone.length==0){
            $("#J_contact_phone").next("span").html("请输入联系电话").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[0-9-_\+]{7,20}$/;
            if(!reg.test(J_contact_phone)){
                $("#J_contact_phone").next("span").html("请输入真实的联系电话").css("color","#cc0000");
                return false;
            }
        }
        if(J_contact_qq.length==0){
            $("#J_contact_qq").next("span").html("请输入QQ号码").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[0-9]{6,20}$/;
            if(!reg.test(J_contact_qq)){
                $("#J_contact_qq").next("span").html("请输入真实的QQ号码").css("color","#cc0000");
                return false;
            }
        }
        if(J_vcode.length==0){
            $("#J_vcode").next("span").html("请输入验证码").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[A-Za-z0-9]{0,4}$/;
            if(!reg.test(J_vcode)){
                $("#J_vcode ~span").html("请输入正确的验证码").css("color","#cc0000");
                return false;
            }
        }

        var invite_code=getUrlParam('ic');
        $.post("/register/register_f/", {
            company_name : J_company_name,
            contact_name : J_contact_name,
            contact_title : J_contact_title,
            contact_email : J_contact_email,
            contact_phone : J_contact_phone,
            contact_qq : J_contact_qq,
            invite_code : invite_code,
            vcode : J_vcode,
            type : J_type
        },function(data){

            var data_res=$.parseJSON(data);
            if(data_res.state=='n'){
                $("#"+data_res.errorid+' ~ span').html(data_res.info).css("color","#cc0000");
                return false;
            }
            if(data_res.state==true){
                $.post("/register/sendemail/", {
                    contact_name : J_contact_name,
                    contact_email : J_contact_email
                },function(data){
                    //
                });

                $("input[type=reset]").trigger("click");
                $("#J-reg-res").html("您的注册申请已提交，我们的客服会尽快联系您。如果有疑问请联系我们。");
                return false;
            }
            if(data_res.state==false){
                $("#J-reg-res").html("您的注册申请提交失败，请重新提交。如果有疑问请联系我们。");
                return false;
            }
        });
    });
    $("#J_register_c_btn").click(function(){

        var J_company_name= $("#J_company_name_c").val();
        var J_contact_name= $("#J_contact_name_c").val();
        var J_contact_title= "";
        var J_contact_email= $("#J_contact_email_c").val();
        var J_contact_phone= "";
        var J_contact_qq= "";
        var J_vcode= $("#J_vcode_c").val();
        var J_type = 2;
        var J_email_vcode= $("#J_email_vcode_c").val();

        if(J_company_name.length==0){
            $("#J_company_name_c").next("span").html("请输入公司名称").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[%&.@#!',;=?$|￥\^*~_\d]*$/;
            if(reg.test(J_company_name)){
                $("#J_company_name_c").next("span").html("请输入真实的公司名称").css("color","#cc0000");
                return false;
            }
            if(J_company_name.length>50){
                $("#J_company_name_c").next("span").html("请输入真实的公司名称").css("color","#cc0000");
                return false;
            }
        }

        if(J_contact_name.length==0){
            $("#J_contact_name").next("span").html("请输入您的姓名").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[\u4E00-\u9FA5A-Za-z]{0,50}$/;
            if(!reg.test(J_contact_name)){
                $("#J_contact_name").next("span").html("请输入真实的姓名").css("color","#cc0000");
                return false;
            }
            if(J_contact_name.length>50){
                $("#J_contact_name").next("span").html("请输入真实的姓名").css("color","#cc0000");
                return false;
            }
        }

        if(J_contact_email.length==0){
            $("#J_contact_email_c").next("span").html("请输入工作邮箱").css("color","#cc0000");
            return false;
        }else{
            var reg=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
            if(!reg.test(J_contact_email)){
                $("#J_contact_email_c").next("span").html("请输入真实的工作邮箱").css("color","#cc0000");
                return false;
            }
        }

        if(J_vcode.length==0){
            $("#J_vcode_c").next("span").html("请输入验证码").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[A-Za-z0-9]{0,4}$/;
            if(!reg.test(J_vcode)){
                $("#J_vcode_c ~span").html("请输入正确的验证码").css("color","#cc0000");
                return false;
            }
        }

        if(J_email_vcode.length==0){
            $("#J_send_email_c").next("span").html("请输入激活码").css("color","#cc0000");
            return false;
        }else{
            var reg=/^[0-9]{6}$/;
            if(!reg.test(J_email_vcode)){
                $("#J_send_email_c ~span").html("请输入正确的激活码").css("color","#cc0000");
                return false;
            }
        }

        var invite_code=getUrlParam('ic');
        $.post("/register/register_f/", {
            company_name : J_company_name,
            contact_name : J_contact_name,
            contact_title : J_contact_title,
            contact_email : J_contact_email,
            contact_phone : J_contact_phone,
            contact_qq : J_contact_qq,
            invite_code : invite_code,
            vcode : J_vcode,
            email_vcode : J_email_vcode,
            type : J_type
        },function(data){
            $("#J_verify_code_m_c").attr('src', '/verify_code?t='+(new Date().getTime()));
            var data_res=$.parseJSON(data);
            if(data_res.state=='n'){
                $("#"+data_res.errorid+'_c ~ span').html(data_res.info).css("color","#cc0000");
                return false;
            }else if(data_res.state=='y'){
                $("#J_send_email_c").next("span").html("");
                $("input[type=reset]").trigger("click");
                $("#J-reg-res-c").html("您的账号已开通，账户信息已发送至您的邮箱，请您注意查收。");
                //异步发送邮件
                $.ajax({
                    'url': '/register/async_sendEmail',
                    'data': {'email_info':data_res.info},
                    'dataType': 'json',
                    'type': 'post',
                    'async':true,
                    'success': function(data) {

                    },
                    'error': function(XMLHttpRequest, textStatus, errorThrown) {
                    }
                });

                return false;
            }
            if(data_res.state==true){
                $("#J_send_email_c").next("span").html("");
                $("input[type=reset]").trigger("click");
                $("#J-reg-res-c").html("您的注册申请已提交，开户成功后账号信息会发送至您的邮箱，请您注意查收。");
                $.post("/register/sendemail_c/", {
                    contact_name : J_contact_name,
                    contact_email : J_contact_email
                },function(data){
                    //
                });
                return false;
            }
            if(data_res.state==false){
                $("#J-reg-res-c").html("您的注册申请提交失败，请重新提交。如果有疑问请联系我们。");
                return false;
            }
        });
    });

    //刷新验证码
    $("#J_verify_code_m").click(function(){
        $("#J_verify_code_m").attr('src', '/verify_code?t='+(new Date().getTime()));
    });
    $("#J_verify_code_m_c").click(function(){
        $("#J_verify_code_m_c").attr('src', '/verify_code?t='+(new Date().getTime()));
    });
    function getUrlParam(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r!=null) return unescape(r[2]); return null; //返回参数值
    }
    //发送激活码
    if(get_cookie('r_e_wait_time')) {
        wait_time($("#J_reg_send_email"),get_cookie('r_e_wait_time'),'r_e_','发送邮箱激活码');
    }
    function wait_time(obj,sendwait,pex,txt) {
        if (sendwait == 0) {
            obj.removeClass("account-f-getcode-no");
            obj.html(txt);
            del_cookie(pex+'wait_time');
        } else {
            set_cookie(pex+'wait_time',sendwait);
            obj.addClass("account-f-getcode-no");
            obj.html(sendwait+"秒后可重新发送");
            sendwait--;
            setTimeout(function() {
                    wait_time(obj,sendwait,pex,txt)
                },
                1000);
        }
    }
    function set_cookie(name,value,expire) {
        var exp = new Date();
        exp.setTime(exp.getTime() + expire);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }
    function get_cookie(name) {
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        if(arr != null)
            return unescape(arr[2]);
        return null;
    }
    function del_cookie(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = get_cookie(name);
        if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
    }
    
       $("img.lazy-load").lazyload({
        effect: "fadeIn", // 载入使用何种效果
         threshold: 50, // 提前开始加载
        failurelimit : 10 // 图片排序混乱时
    });
    
    //查找所有的图片
    select();
    selectforM();
    $(window).on('scroll',function(){
        select();
    });
//检查图片显示
    function select(){
        $('.index-hotel-list img, .index-city-t img, .index-city-b img').not('.isloaded').each(function(){
            if (isVisible($(this))) {
                showImg($(this));
            }
        });
    }
     function selectforM(){
        $('.index-wrap-main-hotel img').not('.isloaded').each(function(){
            showImg($(this));
        });
    }

//加载
    function isVisible($node) {
        var winHe = $(window).height();
        var scrollTop = $(window).scrollTop();
        var offsetTop = $node.offset().top;
        var height = $node.innerHeight();
        if( (winHe + scrollTop ) > offsetTop && (scrollTop < offsetTop + height) ) {
            return true;
        }else {
            return false;
        }
    }
//img属性替换
    function showImg($imgs){
        $imgs.each(function(){
            var url = $(this).attr('data-src');
            $(this).attr('src',url);
            $(this).addClass('isloaded');
        });
    }
	/**
	 * 获取当前时间
	 * @returns {string}
	 */
	function getNowFormatDate() {
		var date = new Date();
		var seperator1 = "-";
		var seperator2 = ":";
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if (month >= 1 && month <= 9) {
			month = "0" + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = "0" + strDate;
		}
		var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
			+ " " + date.getHours() + seperator2 + date.getMinutes()
			+ seperator2 + date.getSeconds();
		return currentdate;
	}

    if(getUrlParam('soh')){
        $('#J_city').focus().select();
    }
    //获取缓存价格
    $('.searchrecord-unit').each(function () {
        var city_id = $(this).find("input[type=hidden][name=city_id]").val();
        var hotel_id = $(this).find("input[type=hidden][name=id]").val();
        var check_in = $(this).find("span.start").attr('data');
        var check_out = $(this).find("span.end").attr('data');
        get_record_price(city_id, hotel_id, check_in, check_out, $(this));
    });
    function get_record_price(city_id, hotel_id, check_in, check_out, $obj) {
        $.ajax({
            type: "POST",
            url: "/haoqiao/get_record_price",
            data: { "city_id": city_id, "hotel_id": hotel_id, "check_in": check_in, "check_out": check_out },
            dataType: 'json',
            success: function (res) {
                if (res.code === 0 && res.data.price_sale) {
                    $obj.find(".currency").show();
                    $obj.find(".price-unit").html(res.data.price_sale);
                }
            },
            error: function () {
            }
        });
    }
})();